<template>
  <div>
    <!-- <van-nav-bar title="收益明细" left-text="返回" right-text="按钮" left-arrow @click-left="onClickLeft" @click-right="onClickRight" /> -->
    <div class="top">
      <div class="w">
        <div class="a">进账：<br />{{ toplist.zhuanru }}</div>
        <div class="a">奖励：<br />{{ toplist.jiangli }}</div>
      </div>
      <div class="w">
        <div class="a">支出：<br />{{ toplist.zhuanchu * -1 }}</div>
        <div class="a">提现：<br />{{ toplist.tixian * -1 }}</div>
      </div>
      <div class="w">
        <div class="a">余额：<br />{{ toplist.yue }}</div>
        <div class="a">消费：<br />{{ toplist.xiaofei }}</div>
      </div>
    </div>
    <div class="list">
      <div class="item" v-for="(item, index) in list" :key="index">
        <div class="top-box">
          <div class="lf">
            {{ item.change_money }}
          </div>
          <div class="rg">
            {{ item.created_at }}
          </div>
        </div>
        <div class="jifen">
          {{ item.remark }}
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { scrollMixin } from "../../../utils/mixin";
export default {
  mixins: [scrollMixin], //加载更多
  data() {
    return {
      list: [],
      toplist: [],
      page: 1, //分页数，当前页数
      isLoadMore: true, //判断是否要加载更多的标志
      total_page: 0 //总页数
    };
  },

  activated() {
    this.getData();
    console.log("hello");
    window.scrollTo(0, 0);
  },
  methods: {
    onClickLeft() {
      Toast('返回');
    },
    onClickRight() {
      Toast('按钮');
    },
    //获取更多数据
    getMoreData() {
      console.log("hongbao", this.isLoadMore);
      if (!this.isLoadMore) return;
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page += 1;
        let json = {
          page: this.page,
          uid: localStorage.getItem("uid")
        };
        let _url = "Yingguang.mingxi";
        $http.post(_url, json).then(response => {
          if (response.result === 1) {
            console.log(response.data, "data");
            var nextPageData = response.data.data;
            this.list = [...this.list, ...nextPageData];
            this.isLoadMore = true;
            console.log(this.list, "ffdfdd");
          } else {
            this.page = this.page - 1;
            this.isLoadMore = false;
          }
        });
      }
    },
    initData() {
      this.page = 1;
      this.isLoadMore = true;
      this.total_page = 0;
    },
    getData() {
      this.initData();
      $http
        .get("Yingguang.mingxi", {
          page: this.page,
          uid: localStorage.getItem("uid")
        })
        .then(response => {
          this.list = response.data.data;
          this.toplist = response.data;

          if (response.result === 1) {
            this.isLoadMore = true;
            this.total_page = response.data.last_page;
            if (!this.total_page) {
              this.total_page = 0;
            }
          }
          console.log(this.list, "成功11111111");
        });
    }
  }
};
</script>
<style scoped>
.top {
  width: 90%;
  height: 150px;
  margin: auto;
  background-color: #ffffff;
  border-radius: 20px;
  margin-top: 20px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.jifen {
  font-size: 13px;
  color: grey;
}
.a {
  padding: 6px;
}
.item {
  width: 90%;
  height: 90px;
  background-color: #ffffff;
  border-radius: 20px;
  margin: auto;
  margin-top: 20px;
}
.top-box {
  width: 100%;
  height: 50px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.lf {
  color: #109276;
}
page {
  background-color: rgba(246, 251, 255, 0.932);
}
</style>
